package servlet;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import service.UserService;
import service.UserServiceImpl;
import user.entity.User;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@WebServlet(name="queryAllServlet",urlPatterns = "/queryAllServlet")
public class queryAllServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
       request.setCharacterEncoding("utf-8");
       response.setContentType("text/html;charset=UTF-8");
        String error = (String)request.getAttribute("error") ;//addError
        request.setAttribute("error",error);
        UserService userService=new UserServiceImpl();
        List<User>users;
        users=userService.queryAll();
            request.setAttribute("user",users);
            request.getRequestDispatcher("user.jsp").forward(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
